﻿using Microsoft.AspNetCore.Authorization;

namespace FastEasyAPI.Controllers
{
    /// <summary>
    /// 测试所用Test
    /// </summary>
    [Route("[controller]")]
    [ApiController]
    public class TestController : ControllerBase
    {
        private readonly ITestService test;

        public TestController(ITestService _test)
        {
            test = _test;
        }

        /// <summary>
        /// 加法
        /// </summary>
        /// <param name="i"></param>
        /// <param name="j"></param>
        /// <returns></returns>
        [HttpGet]
        [Authorize]
        [FastEasyRoute(SwaggerVersion.FastEasy, "SUM")]
        public async Task<int> Sum(int i, int j)
        {
            try
            {
                await test.CreateEntityAsync(new Test());
            }
            catch (Exception)
            {
                throw;
            }
            return test.SUM(i, j);
        }

        /// <summary>
        /// 减法
        /// </summary>
        /// <param name="i"></param>
        /// <param name="j"></param>
        /// <returns></returns>
        [HttpGet]
        [Authorize]
        [FastEasyRoute(SwaggerVersion.FastEasy, "SUB")]
        public int SUB(int i, int j)
        {
            return test.SUB(i, j);
        }

        /// <summary>
        /// 乘法
        /// </summary>
        /// <param name="i"></param>
        /// <param name="j"></param>
        /// <returns></returns>
        [HttpGet]
        [FastEasyRoute(SwaggerVersion.OpenAPI, "MUL")]
        public int MUL(int i, int j)
        {
            return test.MUL(i, j);
        }

        /// <summary>
        /// 除法
        /// </summary>
        /// <param name="i"></param>
        /// <param name="j"></param>
        /// <returns></returns>
        [HttpGet]
        [FastEasyRoute(SwaggerVersion.OpenAPI, "DIV")]
        public int DIV(int i, int j)
        {
            try
            {
                test.DIV(i, j);
            }
            catch (Exception)
            {
                throw;
            }
            return 1;
        }
    }
}